package org.esgl3d.math;

public class Vector3d {

    private static final Vector3d ORIGIN = new Vector3d(0f, 0f, 0f);
    
    public float x;
    public float y;
    public float z;
    
    public Vector3d(final Vector3d other) {
    	x = other.x;
    	y = other.y;
    	z = other.z;
    }

    public Vector3d(float xComp, float yComp, float zComp) {
        x = xComp;
        y = yComp;
        z = zComp;
    }
    
    public Vector3d plus(float xComp, float yComp, float zComp) {
        return new Vector3d(x + xComp, y + yComp, z + zComp);
    }
    
    public Vector3d minus(float xComp, float yComp, float zComp) {
        return new Vector3d(x - xComp, y - yComp, z - zComp);
    }

    public String toString() {
        return "["+x+","+y+","+z+"]";
    }
    
    public Vector3d times(float comp) {
    	return times(comp, comp, comp);
    }

    public Vector3d times(float xComp, float yComp, float zComp) {
        return new Vector3d(x * xComp, y * yComp, z * zComp);
    }

    public Vector3d scale(float scaleValue) {
        return new Vector3d(x * scaleValue, y * scaleValue, z * scaleValue);
    }
    
    public Vector3d divide(float comp) {
    	return new Vector3d(x / comp, y / comp, z / comp);
    }
    
    public float length() {
        return (float) Math.sqrt((x*x)+(y*y)+(z*z));
    }

    public Vector3d normalize() {
        float len = length();
        return new Vector3d(x / len, y / len, z / len);
    }

    public Vector3d times(Vector3d other) {
        return this.times(other.x, other.y, other.z);
    }

    public Vector3d plus(Vector3d other) {
        return this.plus(other.x, other.y, other.z);
    }

    public Vector3d minus(Vector3d other) {
        return this.minus(other.x, other.y, other.z);
    }

    public Vector3d cross(Vector3d other) {
        float newX = y * other.z - other.y * z;
        float newY = z * other.x - other.z * x;
        float newZ = x * other.y - other.x * y;
        return new Vector3d(newX, newY, newZ);
    }

    public float dot(Vector3d other) {
        return x * other.x + y * other.y + z * other.z;
    }

    public Vector3d negative() {
        return new Vector3d(-x, -y, -z);
    }
    
    public void normalizeMutable() {
    	float len = length();
    	x = x / len;
    	y = y / len;
    	z = z / len;
    }

}